package sg.edu.nus.comp.cs4218.impl.extended1;

import static org.junit.Assert.*;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.Vector;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import sg.edu.nus.comp.cs4218.ITool;
import sg.edu.nus.comp.cs4218.extended1.IGrepTool;
import sg.edu.nus.comp.cs4218.extended1.IPipingTool;
import sg.edu.nus.comp.cs4218.extended2.ICutTool;
import sg.edu.nus.comp.cs4218.extended2.IUniqTool;
import sg.edu.nus.comp.cs4218.extended2.IWcTool;
import sg.edu.nus.comp.cs4218.fileutils.ICatTool;
import sg.edu.nus.comp.cs4218.impl.CutTool;
import sg.edu.nus.comp.cs4218.impl.GrepTool;
import sg.edu.nus.comp.cs4218.impl.UniqTool;
import sg.edu.nus.comp.cs4218.impl.WCTool;
import sg.edu.nus.comp.cs4218.impl.fileutils.CatTool;
import sg.edu.nus.comp.cs4218.impl.fileutils.EchoTool;
import sg.edu.nus.comp.cs4218.impl.PipingTool;

public class PipingToolHack {

	private IPipingTool pipingTool;

	@Before
	public void setUp() throws Exception {
		pipingTool = new PipingTool(null);

	}

	@After
	public void tearDown() throws Exception {
		pipingTool = null;

	}

	@Test
	public void testPipeBothNull() {
		ITool leftTool = null;
		ITool rightTool = null;
		String pipeResult = pipingTool.pipe(leftTool, rightTool);
		assertTrue("".equals(pipeResult));
		assertTrue(pipingTool.getStatusCode() != 0);
	}
	
	// @CORRECTED this line -> assertTrue(pipingTool.getStatusCode() == 0);
	@Test
	public void testPipeLeftNull() {
		String[] rightToolArgs = { "Bismillah", "-" };
		ITool leftTool = null;
		IGrepTool rightTool = new GrepTool(rightToolArgs);
		String pipeResult = pipingTool.pipe(leftTool, rightTool);
		assertTrue("".equals(pipeResult));
		assertTrue(pipingTool.getStatusCode() != 0);
	}
	
	// @CORRECTED this line -> assertTrue("",equals(pipeResult));
	@Test
	public void testPipeRightNull() {
		String[] leftToolArgs = { "filenotfound" };
		ICatTool leftTool = new CatTool(leftToolArgs);
		ITool rightTool = null;

		String pipeResult = pipingTool.pipe(leftTool, rightTool);
		//String errorMessage = errContent.toString();
		assertTrue("".equals(pipeResult));
	}
	
	@Test
	//Bug 5
	public void testExecuteNullTool() {
		pipingTool = new PipingTool(null);
		String expected = "";
		String actual = pipingTool.execute(new File(System.getProperty("user.dir")), "xyz");
		assertEquals(1, pipingTool.getStatusCode());
	}

	

}
